package matrix

import C "gitee.com/ljfirst/algo-go-sdk/common/constant"

/**
 * @author ljfirst
 * @version V1.0
 * @date 2023/7/10 02:22
 * @author-Email ljfirst@mail.ustc.edu.cn
 * @blogURL https://blog.csdn.net/ljfirst
 * @description
 **/
type Multiplication struct {
	matrix [][]int
}

func (m *Multiplication) Method(matrixA, matrixB [][]int) [][]int {
	if len(matrixA) == 0 || len(matrixB) == 0 || len(matrixA[0]) == 0 || len(matrixB[0]) == 0 {
		return nil
	}
	rawA := len(matrixA)
	rawB := len(matrixB)
	columnA := len(matrixA[0])
	columnB := len(matrixB[0])
	if rawB != columnA {
		return nil
	}
	m.matrix = make([][]int, rawA)
	for i := 0; i < rawA; i++ {
		m.matrix[i] = make([]int, columnB)
	}
	for i := 0; i < rawA; i++ {
		for j := 0; j < columnB; j++ {
			for k := 0; k < columnA; k++ {
				m.matrix[i][j] += matrixA[i][k] * matrixB[k][j]
			}
		}
	}
	return m.matrix
}

func (m *Multiplication) GetAttribute() *C.Attribute {
	return &C.Attribute{
		Tags: []string{C.Matrix},
		Desc: &C.Desc{
			Name:   "Multiplication",
			NameCn: "矩阵:相乘",
			ParamsDesc: map[string]string{
			},
			Example: map[int]string{
			},
		},
	}
}
